




//import JavaReedInterface;

import java.io.Serializable;





public class Fusion implements Serializable{
	int numStructures;
	int maxFaults;
	JavaReedInterface rsInterface;
	int galoisW;
	int[] rsArray;

	public Fusion(int numStructures, int maxFaults){
		this.numStructures = numStructures;
		this.maxFaults = maxFaults;
		rsInterface = new JavaReedInterface();
		galoisW = 16;
		
        rsArray = new int[numStructures*maxFaults];
        int[][] matrix = JavaReedInterface.genRsMatrix(numStructures, maxFaults, galoisW);
        for (int i = 0; i < numStructures; i++) {
            for (int j = 0; j < maxFaults; j++) {
            	rsArray[i*maxFaults+j]= matrix[i][j];
            }
            
        }
        		
	}
	public int[] getUpdatedCodeWords(int[] codeWords,int oldValue,int newValue,int position) throws InterfaceException{

		//it has to be a valid index
//		if(position >= maxFaults) throw new InterfaceException();
		return rsInterface.update(numStructures, maxFaults, galoisW, codeWords, oldValue, newValue, position);
	}
	
	public int[] getRecoveredData(int[] codeWords,int[] dataWords,int[] erasures) throws InterfaceException{
		return rsInterface.recover(numStructures, maxFaults, galoisW,codeWords,dataWords,erasures);		
	}
	
	public int[] encodeData(int[] codeWords,int[] dataWords) throws InterfaceException{
		return rsInterface.encode(numStructures, maxFaults, galoisW,codeWords,dataWords);
	}
	public int[] getAddedCodeWords(int[] codeWordsCurrent,int[] codeWordsNext){
		return rsInterface.addCodeWords(maxFaults,codeWordsCurrent,codeWordsNext);
	}

	public int getAddedCodes(int code1,int code2){
		return rsInterface.addCodes(code1,code2);
	}

	public int getUpdatedCode(int code,int codeIndex, int oldValue,int newValue,int sourceId) throws InterfaceException{
		int matElement = rsArray[codeIndex*numStructures+sourceId];
	    return rsInterface.updateSingleCode(numStructures , maxFaults, galoisW, code,codeIndex,oldValue, newValue,sourceId,matElement);
	}
	
	public static void main(String[] args) {
		System.out.println("trying to muck with fusion");
		//Fusion.initialize(1, 1);  
	}
	
}
